import { isBoundedFunction, isCallable, isConstructable } from '../utils';
export const attachDocProxySymbol = Symbol('attach-proxy-container');
const boundValueSymbol = Symbol('bound value');
export function getTargetValue(target, value) {
  if (isCallable(value) && !isBoundedFunction(value) && !isConstructable(value)) {
    if (value[boundValueSymbol]) {
      return value[boundValueSymbol];
    }

    const boundValue = value.bind(target);
    Object.keys(value).forEach(key => boundValue[key] = value[key]);
    Object.defineProperty(value, boundValueSymbol, {
      enumerable: false,
      value: boundValue
    });
    return boundValue;
  }

  return value;
}
const getterInvocationResultMap = new Map();
export function getProxyPropertyValue(getter) {
  const getterResult = getterInvocationResultMap.get(getter);

  if (!getterResult) {
    const result = getter();
    getterInvocationResultMap.set(getter, result);
    return result;
  }

  return getterResult;
}